<?php
/**
 * lemocms
 * ============================================================================
 * 版权所有 2018-2027 lemocms，并保留所有权利。
 * 网站地址: https://www.lemocms.com
 * ----------------------------------------------------------------------------
 * 采用最新Thinkphp6实现
 * ============================================================================
 * Author: yuege
 * Date: 2019/8/2
 */
namespace app\admin\controller;
use think\facade\Request;
use think\facade\Db;
use think\facade\View;
class System extends Base {

    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
    }

    public function index(){
        $group =  ['site','email','upload','sms'];

        $list = Db::name('config')
            ->where('type','in',$group)
            ->field('code,value')
            ->column('value','code');

        View::assign('config',json_encode($list));
        return View::fetch();

    }
    //配置首页
    public function site()
    {
        if (Request::isPost()) {
            $data = Request::post();
            foreach ($data as $k=>$v){
               $res =  Db::name('config')->where('code',$k)->update(['value'=>$v]);
            }

            $this->success('保存成功');


        } else {
            $this->error('非法操作');
        }
    }

}